<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" href="assets/mui/css/mui.min.css">
    <link rel="stylesheet" href="assets/fontAwesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/reg.css">
    <script src="assets/zepto/zepto.min.js"></script>
    <script src="assets/mui/js/mui.js"></script>
    <script src="./js/common.js"></script>
</head>

<body>
    <header class="mui-bar mui-bar-nav header">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" href="javascript:history.back(-1)"></a>
        <h1 class="mui-title">注册</h1>
        <a class="mui-icon mui-icon-search mui-pull-right"></a>

    </header>
    <nav class="mui-bar mui-bar-tab footer">
        <a class="mui-tab-item" href="index.html">
            <span class="mui-icon mui-icon-home"></span>
            <span class="mui-tab-label">首页</span>
        </a>
        <a class="mui-tab-item" href="category.html">
            <span class="mui-icon mui-icon-bars"></span>
            <span class="mui-tab-label">分类</span>
        </a>
        <a class="mui-tab-item" href="cart.html">
            <span class="mui-icon fa fa-shopping-cart"></span>
            <span class="mui-tab-label">购物车</span>
        </a>
        <a class="mui-tab-item" href="user.html">
            <span class="mui-icon mui-icon-person"></span>
            <span class="mui-tab-label">会员中心</span>
        </a>
    </nav>
    <div class="mui-content">
        <form class="mui-input-group">
            <div class="mui-input-row">
                <label>用户名</label>
                <input type="text" name="username" class="mui-input-clear" placeholder="请输入用户名">
            </div>
            <div class="mui-input-row">
                <label>手机号码</label>
                <input type="text" name="tel" class="mui-input-clear" placeholder="请输入手机号码">
            </div>
            <div class="mui-input-row">
                <label>密码</label>
                <input type="password" name="pwd" class="mui-input-password" placeholder="请输入密码">
            </div>
            <div class="mui-input-row">
                <label>确认密码</label>
                <input type="password" name="pwd2" class="mui-input-password" placeholder="请输入密码">
            </div>
            <div class="mui-input-row yzm">
                <label>验证码</label>
                <input type="text" name="yzm" class="mui-input-clear" placeholder="请输入验证码">
                <a href="#" class="pull-right">获取验证码</a>
            </div>
            <div class="mui-button-row">
                <button type="button" class=" reg mui-btn mui-btn-primary">注册</button>
            </div>
        </form>
        <a href="login.html" class="mui-pull-right login">立即登录</a>
    </div>
</body>
<script>
    $(".reg").on('tap', function () {
        var username = $('input[name="username"]').val()
        var tel = $('input[name="tel"]').val()
        var pwd = $('input[name="pwd"]').val()
        var pwd2 = $('input[name="pwd2"]').val()
        var yzm = $('input[name="yzm"]').val()
        if (username == "") {
            mui.toast("输入用户名")
            return;
        }
        if (tel == "") {
            mui.toast("输入电话")
            return;
        }
        if (pwd == "" || pwd2 == "") {
            mui.toast("输入密码")
            return;
        }
        if (pwd != pwd2) {
            mui.toast("两次密码不一致")
            return;
        }
        if (yzm == "") {
            mui.toast("输入验证码")
            return;
        }
        $.ajax({
            url: '/user/register',
            type: 'POST',
            data: {
                username: username,
                password: pwd,
                mobile: tel,
                vCode: yzm
            },
            success: function (res) {
                console.log(res)
                if (res.success) {
                    setTimeout(() => {
                        location.href = "login.html"
                    }, 1000);
                } else if (res.error) {
                    mui.toast(res.message)
                }
            }
        })
    })
    $('.yzm a').on('tap', function () {
        $.ajax({
            url: '/user/vCode',
            type: "GET",
            success: function (res) {
                console.log(res)
            }
        })
    })

</script>

</html>
